package com.java.huxb.day06.atomic;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author huxb
 * @date 2020/4/18 0018 上午 8:02
 */
public class TickerThread implements Runnable {

    private Integer ticketCount;
    private  AtomicInteger ticket = new AtomicInteger(100);

    public TickerThread(Integer ticketCount) {
        this.ticketCount = ticketCount;
    }

    public Integer getTicketCount() {
        return ticketCount;
    }

    public void setTicketCount(Integer ticketCount) {
        this.ticketCount = ticketCount;
    }

    @Override
    public void run() {
        while (ticket.get() > 0) {
            System.out.println(Thread.currentThread().getName() + "正在售卖第"+ ticket.get() +"张票"  );
            ticket.decrementAndGet();
        }
    }

}


